package com.itheima.easy.job;

import com.itheima.easy.constant.TradingConstant;
import com.itheima.easy.face.CommonPayFace;
import com.itheima.easy.face.TradingFace;
import com.itheima.easy.vo.TradingVo;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务：支付结果同步
 */
@Component
public class TradeHandlerJob {

    @Autowired
    TradingFace tradingFace;

    @Autowired
    CommonPayFace commonPayFace;

    /***
     * @description 支付结果同步
     * @param param
     * @return
     */
    @XxlJob(value = "tradeHandlerJob")
    public ReturnT<String> execute(String param) {
        //查询最近10分钟内待支付订单
        List<TradingVo> tradingVos = tradingFace.findTradingByTradingState(TradingConstant.TRADE_WAIT_BUYER_PAY);
        //调用API查询接口，获取支付状态
        for (TradingVo tradingVo : tradingVos) {
            commonPayFace.queryTrading(tradingVo);
        }
        ReturnT.SUCCESS.setMsg("执行-支付结果同步-成功");
        return ReturnT.SUCCESS;
    }

}
